package forum.view.converters;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class MyNewLineAppender implements Converter {

	public Object getAsObject(FacesContext facesContext, UIComponent comp, String data) throws ConverterException {
		return data;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object object) throws ConverterException {
		String data = null;
		
		if (object instanceof String){
		data = (String) object;
		BufferedReader br = new BufferedReader(new StringReader(data));
		StringBuilder sb = new StringBuilder();
		String line = null;
		try {
			while((line = br.readLine()) != null){
				//sb.append("<br>"+line+"</br>");
				sb.append(line);
			}
			
			data = sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
		}
		}
		return data;
	}
}
